<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" align="center">
      <el-form-item>
        <el-input
          v-model="searchObj.id"
          class="inline-input"
          placeholder="预约编号"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
        <el-button type="default" @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>
    <el-divider />
    <el-form label-width="500px">
      <el-form-item label="接种医院">
        <el-input v-model="searchObj.hospitalName" readonly="true" style="width: 250px" />
      </el-form-item>
      <el-form-item label="接种者姓名">
        <el-input v-model="searchObj.vaccinatorName" readonly="true" style="width: 250px" />
      </el-form-item>
      <el-form-item label="疫苗名称">
        <el-input v-model="searchObj.vaccineName" readonly="true" style="width: 250px" />
      </el-form-item>
      <el-form-item label="疫苗信息码">
        <el-input v-model="searchObj.vaccineIdcard" style="width: 250px" />
      </el-form-item>
      <el-form-item v-if="searchObj.isState===1">
        <el-button :disabled="saveBtnDisabled" type="primary" @click="update()">保存</el-button>
        <el-button :disabled="saveBtnDisabled" type="danger" @click="cancel()">取消预约</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import Cookies from 'js-cookie'
import appointment from '@/api/appointment'

export default {
  name: 'Searchapp',
  data() {
    return {
      searchObj: {
        id: '',
        vaccinatorName: '',
        vaccineName: '',
        hospitalName: '',
        isState: '',
        vaccineIdcard: '',
        doctorId: ''
      }
    }
  },
  methods: {
    fetchData() {
      // 调用api
      this.searchObj.doctorId = Cookies.get('Sysid')
      console.log(this.searchObj.doctorId)
      appointment.getById(this.searchObj.id)
        .then(response => {
          this.searchObj = response.data.item
        })
    },
    update() {
      this.searchObj.doctorId = Cookies.get('Sysid')
      this.searchObj.isState = 2
      appointment.updateById(this.searchObj).then(response => {
        this.$message({
          type: 'success',
          message: response.message
        })
        this.searchObj = {}
      })
    },
    cancel() {
      this.searchObj.doctorId = Cookies.get('Sysid')
      this.searchObj.isState = 0
      appointment.updateById(this.searchObj).then(response => {
        this.$message({
          type: 'success',
          message: response.message
        })
        this.searchObj = {}
      })
    }

  }

}
</script>

<style scoped>

</style>
